package com.cqie.secondhandtransaction.model;

import com.cqie.secondhandtransaction.model.constants.ResultCode;
import com.cqie.secondhandtransaction.utils.DateUtil;
import com.cqie.secondhandtransaction.utils.JsonUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;


@Setter
@Getter
@ApiModel(value = "Result")
public class Result<T> {
    @ApiModelProperty(value = "返回编码.200=成功")
    private int code = ResultCode.SUCCESS;

    @ApiModelProperty(value = "返回信息")
    private String msg = "ok";

    @ApiModelProperty(value = "当前时间")
    private String time = DateUtil.getDateTime();

    @ApiModelProperty(value = "返回数据")
    private T data;

    public Result() {
    }

    public Result(T data) {
        this.data = data;
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    @Override
    public String toString() {
        return JsonUtil.toJSON(this);
    }

}
